#include <iostream>
using std::cout;
using std::endl;

class Point
{
public:
	Point(double x,double y)
	: _x(x)
	, _y(y)
	{}

	//定义一个成员函数模板
	//将_x转换成目标类型
	template <class T = int>
	T convert()
	{
        /* _x = (T)_x; */
		return (T)_x;
	}

    template <class T>
    T add(T t1);
private:
	double _x;
	double _y;
};

//类外实现成员函数模板时需要加上模板的声明
template <class T>
T Point::add(T t1){
    return _x + _y + t1;
}


void test0(){
    Point pt(1.6,8.9);
    cout << pt.convert() << endl; 
    cout << pt.convert<int>() << endl;
    /* cout << pt._x << endl; */

    cout << pt.add(1.2) << endl;

    Point pt2(6.5,7.7);
    cout << pt2.add(1.1) << endl;

    cout << pt2.add(10) << endl;
}

int main(void){
    test0();
    return 0;
}
